package ToYesterday.Day1103_OfferAppendTail;

import org.junit.Test;

public class Solution {
    class ListNode{
        int x;
        ListNode(int mx){
            x = mx;
        }
    }

    class Stack{
        ListNode [] listNodes;
        int length;
        Stack(){
            listNodes = new ListNode[100];
            length=0;
        }
        int pop(ListNode node){
            if (length<listNodes.length){
                listNodes[length]=node;
                length++;
                return 1;
            }else {
                return 0;
            }
        }
        ListNode push(){
            if (length==0)return null;
            ListNode x = listNodes[length-1];
            length--;
            return x;
        }

    }

    class Queue{
        Stack stack1;
        Stack stack2;
        Queue(){
            stack1 = new Stack();
            stack2 = new Stack();
        }

        int QueuePop(ListNode n1){
            return stack1.pop(n1);
        }

        ListNode QueuePush(){
            if (stack2.length>1)return stack2.push();
            else {
                while (stack1.length>0){
                    ListNode n = stack1.push();
                    stack2.pop(n);
                }
                return stack2.push();
            }
        }
    }
    @Test
    public void Test(){
        ListNode node1 = new ListNode(4);
        ListNode node2 = new ListNode(5);
        ListNode node3 = new ListNode(3);

        Queue queue = new Queue();
        queue.QueuePop(node1);
        queue.QueuePop(node2);
        queue.QueuePush();
        queue.QueuePop(node3);
        System.out.println(queue.QueuePush().x);
    }
}
